package com.zwj.controller;

import com.zwj.bo.*;
import com.zwj.entity.UserEntity;
import com.zwj.service.CourseService;
import com.zwj.utils.TokenUtils;
import com.zwj.vo.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/course")
public class CourseController {
    private final CourseService courseService;
    public CourseController(CourseService courseService) {
        this.courseService = courseService;
    }

    @ApiOperation(value = "添加课程", notes = "添加课程")
    @PostMapping("/admin/addCourse")
    public Result addCourse(@RequestBody AddCourseBo addCourseBo, HttpServletRequest request) {
        UserEntity userEntity = TokenUtils.getUser(request);
        return courseService.addCourse(addCourseBo,userEntity);
    }
    @ApiOperation(value = "选择学生", notes = "选择学生")
    @PostMapping("/admin/chooseCourseStudent")
    public Result chooseCourseStudent(@RequestBody ChooseCourseStudentBo chooseCourseStudentBo, HttpServletRequest request) {
        UserEntity userEntity = TokenUtils.getUser(request);
        return courseService.chooseCourseStudent(chooseCourseStudentBo,userEntity);
    }
    @ApiOperation(value = "查询课程", notes = "查询课程")
    @PostMapping("/selectCourse")
    public Result selectCourse(@RequestBody SelectCourseBo selectCourseBo, HttpServletRequest request) {
        UserEntity userEntity = TokenUtils.getUser(request);
        return courseService.selectCourse(selectCourseBo,null,userEntity);
    }
    @ApiOperation(value = "按ID查询课程", notes = "按ID查询课程")
    @PostMapping("/selectCourseById")
    public Result selectCourseById(@RequestBody SelectCourseByIdBo selectCourseByIdBo, HttpServletRequest request) {
        UserEntity userEntity = TokenUtils.getUser(request);
        return courseService.selectCourse(new SelectCourseBo(),selectCourseByIdBo.getCourseProjectInfoId(),userEntity);
    }
    @ApiOperation(value = "编辑课程", notes = "编辑课程")
    @PostMapping("/admin/updateCourse")
    public Result updateCourse(@RequestBody AddCourseBo addCourseBo, HttpServletRequest request) {
        UserEntity userEntity = TokenUtils.getUser(request);
        return courseService.updateCourse(addCourseBo,userEntity);
    }
    @ApiOperation(value = "删除课程", notes = "删除课程")
    @PostMapping("/admin/deleteCourse")
    public Result deleteCourse(@RequestBody CourseBo courseBo, HttpServletRequest request) {
        UserEntity userEntity = TokenUtils.getUser(request);
        return courseService.deleteCourse(courseBo,userEntity);
    }
    @ApiOperation(value = "查看课程学生", notes = "查看课程学生")
    @PostMapping("/teacher/seeStudent")
    public Result seeStudent(@RequestBody SeeStudentBo seeStudentBo) {
        return courseService.seeStudent(seeStudentBo);
    }
}
